1 using UnityEngine;
2 using
System.Collections;
3
4 public
class SpawnEnemyScript : MonoBehaviour {
5
6     
public GameObject objectToSpawn;
7     
public float timeToWaitBetweenSpawns = 2.0f;
8     
private float timer = 0;
9
10     IronManBehaviorScript behaviorScript;
11
12     
// Use this for initialization
13     
void Start () {
14         timer =
0;
15         GameObject player = GameObject.FindGameObjectWithTag (
"Player");
16         behaviorScript = player.GetComponent<IronManBehaviorScript> ();
17     
18     }
19     
20     
// Update is called once per frame
21     
void Update () {
22         
if (behaviorScript.gameOver == true)
23             
return;
24         
25         timer += Time.deltaTime;
26         
if (timer > timeToWaitBetweenSpawns) {
27             
// todo: spawn the objectToSpawn
28             
// we need to reset the timer
29             Instantiate(objectToSpawn, transform.position, transform.rotation);
30             timer =
0;
31         }
32     
33     }
34 }


Gõ tìm kiếm nhanh...